﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace Sample.JwtBearer.Api.Controllers;

/// <summary>
/// WeatherForecast
/// </summary>
[Authorize]
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
    private static readonly string[] Summaries = new[]
    {
        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
    };

    private readonly ILogger<WeatherForecastController> _logger;

    public WeatherForecastController(ILogger<WeatherForecastController> logger)
    {
        _logger = logger;
    }

    /// <summary>
    /// GetWithParameterless
    /// </summary>
    /// <returns></returns>
    [HttpGet("GetWithParameterless")]
    public IEnumerable<WeatherForecast> Get()
    {
        var rng = Random.Shared;
        return Enumerable.Range(1, 5).Select(index => new WeatherForecast
        {
            Date = DateTime.Now.AddDays(index),
            TemperatureC = rng.Next(-20, 55),
            Summary = Summaries[rng.Next(Summaries.Length)]
        }).ToArray();
    }

    /// <summary>
    /// Get
    /// </summary>
    /// <param name="weatherForecast"></param>
    /// <returns></returns>
    [HttpGet("Get")]
    public IEnumerable<WeatherForecast> Get(WeatherForecast weatherForecast)
    {
        var list = new List<WeatherForecast>
        {
            weatherForecast
        };
        return list;
    }
}

/// <summary>
/// 天气预报样本
/// </summary>
public class WeatherForecast
{
    /// <summary>
    /// 日期
    /// </summary>
    public DateTime Date { get; set; }

    /// <summary>
    /// 温度C
    /// </summary>
    public int TemperatureC { get; set; }

    /// <summary>
    /// 温度F
    /// </summary>
    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

    /// <summary>
    /// 概述
    /// </summary>
    public string Summary { get; set; } = string.Empty;
}
